/*!
 * @文件名 drv_gpio.c
 *
 * @功能描述
 *  1.配置GPIO端口为输入还是输出
 *  2.GPIO读写函数
 */
#include"drv_gpio.h"

static struct gpio_cfg_in_t g_pArrayPortIn[] =
{
    {IN_LVDS_UNLOCK_PORT,      IN_LVDS_UNLOCK_PIN},
    {IN_WAKEUP_PORT,           IN_WAKEUP_PIN},
    {IN_TFT_ERR_PORT,          IN_TFT_ERR_PIN},
    {IN_LDO_1V2_PG_PORT,       IN_LDO_1V2_PG_PIN},
    {IN_SW_3V3_PG_PORT,        IN_SW_3V3_PG_PIN},
    {IN_PMIC_FLTB_PORT,        IN_PMIC_FLTB_PIN},
    {IN_BL_ERR_PORT,           IN_BL_ERR_PIN},
};

static struct gpio_cfg_out_t g_pArrayPortOut[] =
{
    {OUT_BL_PWM_PORT,         	OUT_BL_PWM_PIN,       	GPIO_PIN_LEVEL_LOW},
    {OUT_BL_EN_PORT,          	OUT_BL_EN_PIN,        	GPIO_PIN_LEVEL_LOW},
    {OUT_LVDS_PDB_PORT,       	OUT_LVDS_PDB_PIN,     	GPIO_PIN_LEVEL_HIGH},
    {OUT_PON_HOLD_PORT,       	OUT_PON_HOLD_PIN,     	GPIO_PIN_LEVEL_LOW},
    {OUT_TFT_BIST_PORT,         OUT_TFT_BIST_PIN,       GPIO_PIN_LEVEL_LOW},
    {OUT_TFT_SYBYB_PORT,        OUT_TFT_SYBYB_PIN,      GPIO_PIN_LEVEL_LOW},
    {OUT_TFT_DISP_PORT,         OUT_TFT_DISP_PIN,       GPIO_PIN_LEVEL_LOW},
    {OUT_TFT_SHLR_PORT,         OUT_TFT_SHLR_PIN,       GPIO_PIN_LEVEL_LOW},
    {OUT_TFT_RST_PORT,          OUT_TFT_RST_PIN,        GPIO_PIN_LEVEL_LOW},
    {OUT_TP_RST_PORT,           OUT_TP_RST_PIN,         GPIO_PIN_LEVEL_LOW},
    {OUT_3V3_TFT_EN_PORT,       OUT_3V3_TFT_EN_PIN,     GPIO_PIN_LEVEL_LOW},
    {OUT_PMIC_EN_PORT,          OUT_PMIC_EN_PIN,        GPIO_PIN_LEVEL_LOW},
    {OUT_MCU_INT_PORT,          OUT_MCU_INT_PIN,       	GPIO_PIN_LEVEL_LOW},
    {OUT_LDO_1V2_EN_PORT,       OUT_LDO_1V2_EN_PIN,     GPIO_PIN_LEVEL_LOW},
};

/*FUNCTION**********************************************************************
 *
 * Function Name : bsp_drv_gpio_cfg_input
 * Description   : 配置输入端口
 *
 *END**************************************************************************/
void bsp_drv_gpio_cfg_input(void)
{
    for(uint8_t i=0; i<INPUT_NUM; i++)
    {
    	PINS_DRV_SetPinDirection(g_pArrayPortIn[i].port,g_pArrayPortIn[i].pin,0);
    }
}

/*FUNCTION**********************************************************************
 *
 * Function Name : bsp_drv_gpio_cfg_output
 * Description   : 配置输出端口
 *
 *END**************************************************************************/
void bsp_drv_gpio_cfg_output(void)
{
    for(uint8_t i=0; i<OUTPUT_NUM; i++)
    {
    	PINS_DRV_SetPinDirection(g_pArrayPortOut[i].port,g_pArrayPortOut[i].pin,1);
    	PINS_DRV_WritePin(g_pArrayPortOut[i].port,g_pArrayPortOut[i].pin,g_pArrayPortOut[i].def);
    }
}

/*FUNCTION**********************************************************************
 *
 * Function Name : bsp_drv_gpio_pin_read
 * Description   : 从指定端口读取电平
 *
 *END**************************************************************************/
pins_channel_type_t bsp_drv_gpio_pin_read(int index)
{
    if(index >= INPUT_NUM)return -1;
    pins_channel_type_t read_pins;
    read_pins = PINS_DRV_ReadPins(g_pArrayPortIn[index].port);
    return  (read_pins>>g_pArrayPortIn[index].pin)&0x01;
}

/*FUNCTION**********************************************************************
 *
 * Function Name : bsp_drv_gpio_pin_write
 * Description   : 输出高低电平到指定端口
 *
 *END**************************************************************************/
void bsp_drv_gpio_pin_write(int index, gpio_pin_level_t status)
{
    if(index >= OUTPUT_NUM)return;
    PINS_DRV_WritePin(g_pArrayPortOut[index].port,g_pArrayPortOut[index].pin,status);
}
